//---------------------------------------------------------------------
//  This file is part of the Background Motion solution.
// 
//  Copyright (C) Mindscape (TM).  All rights reserved.
//  http://www.mindscape.co.nz
// 
//  THIS CODE AND INFORMATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY
//  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//  PARTICULAR PURPOSE.
//---------------------------------------------------------------------

using System.Security.Principal;

namespace Mindscape.BackgroundMotion.Model.Security
{
  /// <summary>
  /// Represents an authenticated user of the system
  /// </summary>
  /// <remarks>
  /// This custom identity wraps the association between an authenticated user and the member of the system which they have
  /// identified themselves as
  /// </remarks>
  public class BackgroundMotionIdentity : IIdentity
  {
    private Member _member;

    /// <summary>
    /// Initializes a new instance of the <see cref="BackgroundMotionIdentity"/> class.
    /// </summary>
    public BackgroundMotionIdentity()
    {
    }

    /// <summary>
    /// Initializes a new instance of the <see cref="BackgroundMotionIdentity"/> class.
    /// </summary>
    /// <param name="member">The member.</param>
    public BackgroundMotionIdentity(Member member)
    {
      _member = member;
    }

    /// <summary>
    /// The member which this user has authenticated as
    /// </summary>
    public Member Member
    {
      get { return _member; }
      set { _member = value; }
    }

    /// <summary>
    /// The unique identifier of the member which this user has authenticated as
    /// </summary>
    public int MemberId
    {
      get { return _member.Id; }
    }

    /// <summary>
    /// Gets the name of the current user.
    /// </summary>
    /// <value></value>
    /// <returns>The name of the user on whose behalf the code is running.</returns>
    public string Name
    {
      get { return _member.Username; }
    }

    /// <summary>
    /// Gets the type of authentication used.
    /// </summary>
    /// <value></value>
    /// <returns>The type of authentication used to identify the user.</returns>
    public string AuthenticationType
    {
      get { return "Background Motion"; }
    }

    /// <summary>
    /// Gets a value that indicates whether the user has been authenticated.
    /// </summary>
    /// <value></value>
    /// <returns>true if the user was authenticated; otherwise, false.</returns>
    public bool IsAuthenticated
    {
      get { return (_member != null); }
    }
  }
}